<template>
  <div class="app-container">
    <el-tabs
      v-model="tabNum"
      @tab-click="handleClick"
      style="padding: 10px 0 10px 10px;background:#fff;"
    >
      <el-tab-pane
        label="待审批"
        name="1"
      >
        <div
          v-if="tabNum=='1'"
          class="chart-container"
        >
          <avue-crud
            :option="option"
            ref="crud"
            :data="data"
            :table-loading="loading"
            :page.sync="page"
            @on-load="onLoad"
            @current-change="currentChange"
            @row-del="rowDel"
            @selection-change="selectionChange"
            @search-change="searchChange"
            @search-reset="resetChange"
          >
            <template
              slot="icon"
              slot-scope="scope"
            >
              <div v-if="scope.row.icon">
                <svg-icon :icon-class="scope.row.icon"></svg-icon>
              </div>
            </template>
            <template
              slot-scope="{type,size,row}"
              slot="menu"
            >
              <el-button
                :size="size"
                :type="type"
                @click="celCustomer(row)"
                v-has="'authExamineCheck'"
              >审核</el-button>
            </template>
            <auth
              :openDialog="openDialog"
              :title="title"
              ref="auth"
              @save="save"
              @handleReset="handleReset"
            />

          </avue-crud>
          <el-dialog
            title="审核"
            class="avue-dialog"
            center
            :visible.sync="openCel"
            width="55%"
          >
            <div
              class="message"
              v-loading="celLoading"
            >
              <div class="module">
                <el-tabs v-model="basicinfo">
                  <el-tab-pane
                    label="基本信息"
                    name="first"
                  >
                    <table class="detailtable">
                      <tr>
                        <td width="20%">企业名称:</td>
                        <td>{{shList.companyName}}</td>
                        <td width="25%">统一社会信用代码:</td>
                        <td>{{shList.shtyxydm}}</td>
                      </tr>
                      <tr>
                        <td width="20%">法人姓名:</td>
                        <td>{{shList.fddbr}}</td>
                        <td width="25%">联系方式:</td>
                        <td>{{shList.lxdh}}</td>
                      </tr>
                      <tr>
                        <td width="20%">授权渠道:</td>
                        <td colspan="3">{{shList.bank | bankFilter(bankOptions)}}</td>
                        <!--                                                <td>{{dataList.sshy}}</td>-->
                      </tr>
                    </table>
                  </el-tab-pane>
                </el-tabs>
              </div>
              <div class="module">
                <el-tabs v-model="basicinfo">
                  <el-tab-pane
                    label="上传材料"
                    name="first"
                  >
                    <el-image
                      v-for="item in srcList"
                      :key="item"
                      style="width: 200px; height: 200px"
                      :src="item"
                      :preview-src-list="srcList"
                    ></el-image>
                    <!-- <el-image
                                                style="width: 200px; height: 200px"
                                                :src="srcList[0]"
                                                :preview-src-list="srcList">
                                        </el-image> -->
                  </el-tab-pane>
                </el-tabs>
              </div>
              <div class="module">
                <el-tabs v-model="basicinfo">
                  <el-tab-pane
                    label="审核信息"
                    name="first"
                  >
                    <el-form
                      ref="sh"
                      :model="shList"
                      inline
                      :rules="rules"
                    >
                      <el-row>
                        <el-form-item label="审批结果">
                          <el-radio
                            v-model="shList.ty"
                            label="1"
                          >同意</el-radio>
                          <el-radio
                            v-model="shList.ty"
                            label="3"
                          >不同意</el-radio>
                        </el-form-item>
                      </el-row>
                      <el-row>
                        <el-form-item
                          label="备注"
                          v-if="shList.ty == 3"
                          prop="mark"
                        >
                          <el-input
                            v-model="shList.mark"
                            :cols="50"
                            :rows="4"
                            type="textarea"
                            placeholder="请输入备注"
                          ></el-input>
                        </el-form-item>
                      </el-row>
                    </el-form>
                  </el-tab-pane>
                </el-tabs>
              </div>
              <div class="dialog-footer">
                <el-button
                  @click="openCel = false"
                  type="primary"
                  plain
                  round
                >取消</el-button>
                <el-button
                  type="primary"
                  @click="shSubmit"
                  round
                >保存</el-button>
              </div>
            </div>
          </el-dialog>
        </div>
      </el-tab-pane>
      <el-tab-pane
        label="已审批"
        name="2"
      >
        <div
          v-if="tabNum=='2'"
          class="chart-container"
        >
          <avue-crud
            :option="option1"
            ref="crud"
            :data="data"
            :table-loading="loading"
            :page.sync="page1"
            @on-load="onLoad1"
            @current-change="currentChange1"
            @row-del="rowDel"
            @selection-change="selectionChange1"
            @search-change="searchChange1"
            @search-reset="resetChange1"
          >
            <template
              slot="icon"
              slot-scope="scope"
            >
              <div v-if="scope.row.icon">
                <svg-icon :icon-class="scope.row.icon"></svg-icon>
              </div>
            </template>
            <template
              slot-scope="{type,size,row}"
              slot="menu"
            >
              <el-button
                :size="size"
                :type="type"
                @click="checkOpen(row)"
              >查看</el-button>
              <el-button
                v-if="row.authFlg == '1' && row.openStatus == '1'"
                :size="size"
                :type="type"
                @click="start(row,'0')"
                v-has="'authExamineBan'"
              >禁用</el-button>
              <el-button
                v-if="row.authFlg == '1' && row.openStatus != '1'"
                :size="size"
                :type="type"
                @click="start(row,'1')"
                v-has="'authExamineOpen'"
              >启用</el-button>
            </template>
            <!-- <template slot-scope="{type,size,row}" slot="menu">
                        </template> -->
            <auth
              :openDialog="openDialog"
              :title="title"
              ref="auth"
              @save="save"
              @handleReset="handleReset"
            />
          </avue-crud>
          <el-dialog
            title="查看"
            class="avue-dialog"
            center
            :visible.sync="openCell"
            width="60%"
          >
            <div
              class="message"
              v-loading="checkLoading"
            >
              <div class="module">
                <el-tabs v-model="basicinfo">
                  <el-tab-pane
                    label="基本信息"
                    name="first"
                  >
                    <table class="detailtable">
                      <tr>
                        <td width="20%">企业名称:</td>
                        <td>{{yshList.companyName}}</td>
                        <td width="25%">统一社会信用代码:</td>
                        <td>{{yshList.shtyxydm}}</td>
                      </tr>
                      <tr>
                        <td width="20%">法人姓名:</td>
                        <td>{{yshList.fddbr}}</td>
                        <td width="25%">联系方式:</td>
                        <td>{{yshList.lxdh}}</td>
                      </tr>
                      <tr>
                        <td width="20%">授权渠道:</td>
                        <td colspan="3">{{yshList.bank | bankFilter(bankOptions)}}</td>
                      </tr>
                    </table>
                  </el-tab-pane>
                </el-tabs>
              </div>
              <div class="module">
                <el-tabs v-model="basicinfo">
                  <el-tab-pane
                    label="上传材料"
                    name="first"
                  >
                    <el-image
                      v-for="item in ysrcList"
                      :key="item"
                      style="width: 200px; height: 200px"
                      :src="item"
                      :preview-src-list="ysrcList"
                    ></el-image>
                    <!-- <el-image
                                                style="width: 200px; height: 200px"
                                                :src="ysrcList[0]"
                                                :preview-src-list="ysrcList">
                                        </el-image> -->
                  </el-tab-pane>
                </el-tabs>
              </div>
              <div
                class="module"
                style="padding-bottom:20px;"
              >
                <el-tabs v-model="basicinfo">
                  <el-tab-pane
                    label="审批记录"
                    name="first"
                  >
                    <el-table
                      :data="yshList.recordList"
                      style="width: 100%"
                      border
                    >
                      <el-table-column
                        type="index"
                        label="序号"
                        width="100"
                        align="center"
                      >
                      </el-table-column>
                      <el-table-column
                        prop="createTime"
                        label="创建时间"
                        min-width="10%"
                        align="center"
                      >
                      </el-table-column>
                      <el-table-column
                        prop="authTime"
                        label="审批时间"
                        min-width="10%"
                        align="center"
                      >
                      </el-table-column>
                      <el-table-column
                        prop="authFlag"
                        label="授权结果"
                        min-width="10%"
                        align="center"
                      >
                        <template slot-scope="scope">
                          <span v-if="scope.row.authFlag == '1'">授权成功</span>
                          <span v-if="scope.row.authFlag == '3'">授权失败</span>
                        </template>
                      </el-table-column>
                      <el-table-column
                        prop="comment"
                        label="备注"
                        min-width="10%"
                        align="center"
                      >
                      </el-table-column>
                    </el-table>
                  </el-tab-pane>
                </el-tabs>
              </div>
            </div>
          </el-dialog>
          <el-dialog
            title="新增"
            class="avue-dialog"
            :visible.sync="box"
            width="55%"
          >
            <el-form
              ref="form"
              :model="form"
              inline
            >
              <el-form-item label="企业">
                <el-input
                  v-model="form.shtyxydm"
                  placeholder="请输入统一社会信用代码"
                  prefix-icon="el-icon-search"
                ></el-input>
              </el-form-item>
              <el-form-item>
                <el-button
                  type="primary"
                  @click="onSearch"
                  round
                >查询</el-button>
              </el-form-item>
              <div
                class="message"
                v-if="show"
              >
                <div class="module">
                  <el-tabs v-model="basicinfo">
                    <el-tab-pane
                      label="基本信息"
                      name="first"
                    >
                      <table class="detailtable">
                        <tr>
                          <td width="15%">企业名称:</td>
                          <td>{{dataList.qymc}}</td>
                          <td width="25%">统一社会信用代码:</td>
                          <td>{{dataList.shtyxydm}}</td>
                        </tr>
                        <tr>
                          <td width="15%">法人姓名:</td>
                          <td>{{dataList.fddbr}}</td>
                          <td width="25%">联系方式:</td>
                          <td>{{dataList.lxdh}}</td>
                        </tr>
                        <tr>
                          <td width="15%">授权渠道:</td>
                          <!--                                                <td>{{dataList.sshy}}</td>-->
                        </tr>
                        <tr>
                          <td width="15%">注册地址:</td>
                          <td>{{dataList.dz}}</td>
                          <td></td>
                          <td></td>
                        </tr>
                      </table>
                    </el-tab-pane>
                  </el-tabs>
                </div>
                <div class="module">
                  <el-tabs v-model="basicinfo">
                    <el-tab-pane
                      label="上传材料"
                      name="first"
                    >
                      <el-upload
                        class="upload-demo"
                        ref="upload"
                        action=""
                        :accept="acceptFileType"
                        :limit="5"
                        :on-exceed="handleExceed"
                        :before-upload="beforeUpload"
                        :on-preview="handlePreview"
                        :on-remove="handleRemove"
                        :file-list="fileList"
                        :auto-upload="false"
                      >
                        <el-button
                          slot="trigger"
                          size="small"
                          type="primary"
                        >添加</el-button>
                        <div
                          slot="tip"
                          class="el-upload_tip"
                        ></div>
                      </el-upload>
                    </el-tab-pane>
                  </el-tabs>
                </div>
                <div class="dialog-footer">
                  <el-button
                    @click="openDialog_ = false"
                    type="primary"
                    plain
                    round
                  >取消</el-button>
                  <el-button
                    type="primary"
                    @click="submit"
                    round
                  >保存</el-button>
                </div>
              </div>
            </el-form>
          </el-dialog>
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import {
  getAuthList,
  searchAuthById,
  updateApproveAuth,
  updateApprOpenSatus,
  assignC,
  upAssign,
  celC,
  getCUser,
  getAllC,
} from '@/api/manager.js'
import auth from './auth'
import mixin from './mixin'
export default {
  components: {
    auth,
  },
  mixins: [mixin],
  data() {
    return {
      tabNum: '1',
      loading: false,
      form: {},
      dataList: {},
      bankOptions: [],

      searchList: { authFlg: 2 },
      searchList1: { authFlg: '1,3' },

      uploadTemplateDialog: false,
      fileList: [],
      uploadLoading: false,
      acceptFileType: '.pdf,.jpg,.xls',
      downLoadLoading: '',
      checkLoading: false,
      openCel: false,
      shList: {
        data: [],
      },
      srcList: [],
      rules: {
        mark: [{ required: true, message: '请填写备注', trigger: 'blur' }],
      },
      openCell: false,
      celLoading: false,
      yshList: {},
      ysrcList: [],
      /* 分页 */
      page: {
        pageSize: 10,

        pageSizes: [10, 20, 30, 40, 50, 100],
        pagerCount: 5,
        layout: 'total, sizes, prev, pager, next, jumper',

        currentPage: 1,
        total: 0,
        background: false,
      },
      page1: {
        pageSize: 10,

        pageSizes: [10, 20, 30, 40, 50, 100],
        pagerCount: 5,
        layout: 'total, sizes, prev, pager, next, jumper',

        currentPage: 1,
        total: 0,
        background: false,
      },
      // 显示窗口
      openDialog: false,
      title: '新增',
      show: false,

      basicinfo: 'first',
      data: [],
      selectionList: [],
      option: {
        headerAlign: 'center',
        align: 'center',
        border: true,
        index: true,
        indexLabel: '序号',
        indexWidth: 100,
        card: true,
        defaultExpandAll: true,
        dialogDrag: false,
        labelWidth: 120,
        viewBtn: false,
        addBtn: false,
        editBtn: false,
        delBtn: false,

        columnBtn: false,
        refreshBtn: false,
        selectClearBtn: false,
        // searchBtn: true,
        // searchSpan: 9,
        searchShowBtn: false,
        selection: false,
        searchLabelWidth: '20%',
        menuWidth: 150,
        searchSpan: 8,
        searchMenuSpan: 4,
        column: [
          {
            label: '企业名称',
            prop: 'companyName',
            display: false,
            search: true,
          },
          {
            label: '社会统一信用代码',
            prop: 'shtyxydm',
            display: false,
            search: true,
            searchLabelWidth: '35%',
          },
          {
            label: '法人姓名',
            prop: 'fddbr',
            display: false,
          },
          {
            label: '授权渠道',
            prop: 'bank',
            display: false,
            search: true,
            type: 'select',
            dicData: [],
          },
          /* {
                            label: '所属区域',
                            prop: 'address',
                            searchSpan:8,
                            display: false,
                            search: true
                        }, */
          {
            label: '创建时间',
            prop: 'createTime',
            display: false,
          },

          {
            label: '状态',
            prop: 'authFlg',
            display: false,
            search: false,
            type: 'select',
            dicData: [
              {
                label: '待提交',
                value: '0',
              },
              {
                label: '授权成功',
                value: '1',
              },
              {
                label: '待审批',
                value: '2',
              },
              {
                label: '授权失败',
                value: '3',
              },
            ],
          },
          {
            label: '日期范围',
            prop: 'daterange',
            type: 'daterange',
            format: 'yyyy-MM-dd',
            valueFormat: 'yyyy-MM-dd',
            startPlaceholder: '日期开始范围自定义',
            endPlaceholder: '日期结束范围自定义',
            display: false,
            search: true,
            searchRange: true,
            hide: true,
          },
          {
            label: '上传人',
            prop: 'userName',
            search: true,
            display: false,
            searchLabelWidth: '35%',
          },
        ],
        group: [
          {
            icon: 'el-icon-info',
            label: '企业信息',
            collapse: true,
            column: [
              {
                label: '企业名称',
                prop: 'qymc',
              },
              {
                label: '社会统一信用代码',
                prop: 'shtyxydm',
              },
              {
                label: '注册时间',
                prop: 'clrq',
              },
              {
                label: '注册资金',
                prop: 'zczb',
              },
              {
                label: '企业类型',
                prop: 'qylx',
                type: 'select',
                dicData: [
                  {
                    label: '小微企业',
                    value: '1',
                  },
                  {
                    label: '中型企业',
                    value: '2',
                  },
                  {
                    label: '大型企业',
                    value: '3',
                  },
                  {
                    label: '超大型企业',
                    value: '4',
                  },
                  {
                    label: '个体工商户',
                    value: '5',
                  },
                ],
              },
              {
                label: '所属行业',
                prop: 'sshy',
                type: 'select',
                dicData: [
                  {
                    label: '请选择',
                    value: '',
                  },
                  {
                    label: '农林牧渔业',
                    value: '0',
                  },
                  {
                    label: '教育',
                    value: '1',
                  },
                  {
                    label: '采矿业',
                    value: '2',
                  },
                ],
              },
              {
                label: '注册地址',
                prop: 'zs',
                // }, {
                //     label: '企业性质',
                //     prop: 'qyxz',
              },
              {
                label: '企业联系方式',
                prop: 'dh',
              },
              {
                label: '企业综合评分',
                prop: 'score',
              },
            ],
          },
          {
            icon: 'el-icon-info',
            label: '法人信息',
            collapse: true,
            column: [
              {
                label: '法人姓名',
                prop: 'fddbr',
              },
              {
                label: '性别',
                prop: 'xb',
                type: 'select',
                dicData: [
                  {
                    label: '男',
                    value: '1',
                  },
                  {
                    label: '女',
                    value: '0',
                  },
                ],
              },
              {
                label: '出生日期',
                // type: 'csrq',
                prop: 'csrq',
              },
              {
                label: '籍贯',
                prop: 'jg',
              },
              {
                label: '婚姻状况',
                prop: 'hyzk',
                type: 'select',
                dicData: [
                  {
                    label: '已婚',
                    value: '1',
                  },
                  {
                    label: '未婚',
                    value: '0',
                  },
                ],
              },
              {
                label: '学历',
                prop: 'xl',
                type: 'select',
                dicData: [
                  {
                    label: '请选择',
                    value: '',
                  },
                  {
                    label: '专科',
                    value: '0',
                  },
                  {
                    label: '本科',
                    value: '1',
                  },
                  {
                    label: '其他',
                    value: '2',
                  },
                ],
              },

              {
                label: '身份证',
                prop: 'sfzjhm',
              },
              {
                label: '手机号',
                prop: 'lxdh',
              },
              {
                label: '邮箱',
                prop: 'yx',
              },
              {
                label: '联系地址',
                prop: 'dz',
              },
            ],
          },
        ],
      },
      option1: {
        headerAlign: 'center',
        align: 'center',
        border: true,
        index: true,
        indexLabel: '序号',
        indexWidth: 100,
        card: true,
        defaultExpandAll: true,
        dialogDrag: false,
        labelWidth: 135,
        viewBtn: false,
        addBtn: false,
        editBtn: false,
        delBtn: false,

        columnBtn: false,
        refreshBtn: false,
        selectClearBtn: false,
        // searchBtn: true,
        // searchSpan: 9,
        searchShowBtn: false,
        selection: false,
        searchLabelWidth: '20%',
        menuWidth: 150,
        searchSpan: 8,
        searchMenuSpan: 4,
        column: [
          {
            label: '企业名称',
            prop: 'companyName',
            display: false,
            search: true,
          },
          {
            label: '社会统一信用代码',
            prop: 'shtyxydm',
            display: false,
            search: true,
            searchLabelWidth: '35%',
          },
          {
            label: '法人姓名',
            prop: 'fddbr',
            width: 100,
            display: false,
          },
          {
            label: '授权渠道',
            prop: 'bank',
            display: false,
            search: true,
            type: 'select',
            dicData: [],
          },
          {
            label: '状态',
            prop: 'authFlg',
            display: false,
            search: true,
            width: 100,
            type: 'select',
            dicData: [
              {
                label: '授权成功',
                value: '1',
              },
              {
                label: '授权失败',
                value: '3',
              },
            ],
          },
          {
            label: '创建时间',
            prop: 'createTime',
            display: false,
          },
          {
            label: '审批时间',
            prop: 'authTime',
            display: false,
          },
          {
            label: '上传人',
            prop: 'userName',
            search: true,
            display: false,
            searchLabelWidth: '35%',
          },
        ],
        group: [
          {
            icon: 'el-icon-info',
            label: '企业信息',
            collapse: true,
            column: [
              {
                label: '企业名称',
                prop: 'qymc',
              },
              {
                label: '社会统一信用代码',
                prop: 'shtyxydm',
              },
              {
                label: '注册时间',
                prop: 'clrq',
              },
              {
                label: '注册资金',
                prop: 'zczb',
              },
              {
                label: '企业类型',
                prop: 'qylx',
                type: 'select',
                dicData: [
                  {
                    label: '小微企业',
                    value: '1',
                  },
                  {
                    label: '中型企业',
                    value: '2',
                  },
                  {
                    label: '大型企业',
                    value: '3',
                  },
                  {
                    label: '超大型企业',
                    value: '4',
                  },
                  {
                    label: '个体工商户',
                    value: '5',
                  },
                ],
              },
              {
                label: '所属行业',
                prop: 'sshy',
                type: 'select',
                dicData: [
                  {
                    label: '请选择',
                    value: '',
                  },
                  {
                    label: '农林牧渔业',
                    value: '0',
                  },
                  {
                    label: '教育',
                    value: '1',
                  },
                  {
                    label: '采矿业',
                    value: '2',
                  },
                ],
              },
              {
                label: '注册地址',
                prop: 'zs',
                // }, {
                //     label: '企业性质',
                //     prop: 'qyxz',
              },
              {
                label: '企业联系方式',
                prop: 'dh',
              },
              {
                label: '企业综合评分',
                prop: 'score',
              },
            ],
          },
          {
            icon: 'el-icon-info',
            label: '法人信息',
            collapse: true,
            column: [
              {
                label: '法人姓名',
                prop: 'fddbr',
              },
              {
                label: '性别',
                prop: 'xb',
                type: 'select',
                dicData: [
                  {
                    label: '男',
                    value: '1',
                  },
                  {
                    label: '女',
                    value: '0',
                  },
                ],
              },
              {
                label: '出生日期',
                // type: 'csrq',
                prop: 'csrq',
              },
              {
                label: '籍贯',
                prop: 'jg',
              },
              {
                label: '婚姻状况',
                prop: 'hyzk',
                type: 'select',
                dicData: [
                  {
                    label: '已婚',
                    value: '1',
                  },
                  {
                    label: '未婚',
                    value: '0',
                  },
                ],
              },
              {
                label: '学历',
                prop: 'xl',
                type: 'select',
                dicData: [
                  {
                    label: '请选择',
                    value: '',
                  },
                  {
                    label: '专科',
                    value: '0',
                  },
                  {
                    label: '本科',
                    value: '1',
                  },
                  {
                    label: '其他',
                    value: '2',
                  },
                ],
              },

              {
                label: '身份证',
                prop: 'sfzjhm',
              },
              {
                label: '手机号',
                prop: 'lxdh',
              },
              {
                label: '邮箱',
                prop: 'yx',
              },
              {
                label: '联系地址',
                prop: 'dz',
              },
            ],
          },
        ],
      },

      /* 配置弹窗 */
      box: false,
      customerLoading: false,
      handleType: 'add',
      customerForm: {},
      customerPage: {
        page: 1,
        size: 5,
        total: 0,
      },
      /* 已选中 客户经理 */
      customerSelectionList: [],
      customerData: [],
      customerOption: {
        headerAlign: 'center',
        align: 'center',
        border: true,
        // index: true,
        // indexLabel: '序号',
        indexWidth: 100,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        menu: false,
        selection: true,
        reserveSelection: true,
        dialogDrag: false,
        columnBtn: false,
        refreshBtn: false,
        selectClearBtn: false,
        // searchBtn: true,
        // searchSpan: 9,
        searchShowBtn: false,

        column: [
          {
            label: '工号',
            prop: 'eid',
          },
          {
            label: '姓名',
            prop: 'userName',
          },
          {
            label: '性别',
            prop: 'userGender',
            type: 'select',
            dicData: [
              {
                label: '男',
                value: false,
              },
              {
                label: '女',
                value: true,
              },
            ],
          },
          {
            label: '联系方式',
            prop: 'userPhone',
          },
          // {
          //     label: '所属机构',
          //     prop: 'deptCode'
          // },
          {
            label: '所属部门',
            prop: 'province',
          },
        ],
      },
    }
  },
  filters: {
    bankFilter(val, option) {
      if (!val) return ''
      return (
        option.filter((item) => item.value == val).map((ite) => ite.label)[0] ||
        val
      )
    },
  },
  created() {
    this.getDict()
  },
  methods: {
    async getDict() {
      const dataSQQD = await this.$store.dispatch('asyncApi/getDict', {
        code: 'SQQD',
      })
      this.bankOptions = dataSQQD
      this.option.column[3].dicData = dataSQQD
      this.option1.column[3].dicData = dataSQQD
    },
    handleClick(e) {
      /* if(e.name == '1'){
                    this.searchList = {authFlg:2}
                }else{
                    this.searchList1 = {authFlg:'1,3'}
                } */
    },
    onLoad(page, params = {}) {
      let searchList = this.searchList
      Object.assign(params, {
        ...searchList,
        authFlg: '2',
        pageNum: this.page.currentPage,
        pageSize: this.page.pageSize,
      })

      /*Object.assign(params, {
                    pageNum: this.page.currentPage,
                    pageSize: this.page.pageSize
                })*/

      this.loading = true
      getAuthList(params).then((data) => {
        if (data.status) {
          this.loading = false
          this.data = data.data.records
          this.page.total = data.data.total
        }
      })
    },
    onLoad1(page, params = {}) {
      let searchList = this.searchList1
      let authFlg = searchList.authFlg
      if (!authFlg) {
        searchList.authFlg = '1,3'
      }
      Object.assign(params, {
        ...searchList,
        pageNum: this.page1.currentPage,
        pageSize: this.page1.pageSize,
      })
      this.loading = true
      getAuthList(params).then((data) => {
        if (data.status) {
          this.loading = false
          this.data = data.data.records
          this.page1.total = data.data.total
        }
      })
    },
    /* 清空 */
    resetChange(params) {
      params.daterange = []
      this.page.currentPage = 1
      this.page.pageSize = 10
      this.searchList = {}
      this.onLoad()
    },
    /* 搜索筛选 */
    searchChange(params, done) {
      done()
      this.page.currentPage = 1
      this.page.pageSize = 10
      if (params.daterange) {
        params.startTime = params.daterange[0]
        params.endTime = params.daterange[1]
      }
      params.daterange = []
      this.searchList = {
        ...params,
      }
      this.onLoad()
    },
    /* 改变页码 */
    currentChange(currentPage) {
      this.page.currentPage = currentPage
    },
    customerChange(i) {
      this.customerPage.currentPage = i
    },
    /* 选中客户回调 */
    selectionChange(list) {
      this.selectionList = list
    },
    /* 清空 */
    resetChange1() {
      this.page1.currentPage = 1
      this.page1.pageSize = 10
      this.searchList1 = {}
      this.onLoad1()
    },
    /* 搜索筛选 */
    searchChange1(params, done) {
      done()
      this.page1.currentPage = 1
      this.page1.pageSize = 10
      this.searchList1 = {
        ...params,
      }
      this.onLoad1()
    },
    /* 改变页码 */
    currentChange1(currentPage) {
      this.page1.currentPage = currentPage
    },
    customerChange1(i) {
      this.customerPage.currentPage = i
    },
    /* 选中客户回调 */
    selectionChange1(list) {
      this.selectionList = list
    },
    /* 角色配置 */
    handleGrant(e) {
      // if (this.selectionList.length === 0) {
      //     this.$message.warning("请选择至多一条数据");
      //     return;
      // } else if (this.selectionList.length > 1) {
      //     this.$message.warning("请选择至多一条数据");
      //     return;
      // } else {
      this.handleType = e
      this.box = true
      // }
    },
    /* 用户 && 角色列表行点击row选中 */
    rowClick(row) {
      this.data.map((item) => {
        if (item.shtyxydm == row.shtyxydm) {
          this.$refs.crud.toggleSelection()
          this.$refs.crud.toggleSelection([item])
        }
      })
    },
    /* 删除 */
    rowDel(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        delOrg({
          id: row.id,
        }).then(() => {
          this.onLoad(this.page)
          this.$message({
            type: 'success',
            message: '操作成功!',
          })
        })
      })
    },

    /* 选中客户经理回调 */
    customerSelectionChange(list) {
      if (list.length <= 1) {
        this.customerSelectionList = list
      } else {
        this.$refs.cutomer_crud.toggleSelection()
        this.$message.error('请选择单个角色分配!')
      }
    },
    customerRowClick(row) {
      this.customerData.map((item) => {
        if (item.id == row.id) {
          this.$refs.customer_crud.toggleSelection()
          this.$refs.customer_crud.toggleSelection([item])
        }
      })
    },
    /* 获取客户经理列表 */
    onCustomerLoad(page, params = {}) {
      if (page.layout) {
        Object.assign(params, {
          page: 1,
          size: 10,
        })
      } else {
        Object.assign(params, page)
      }
      this.customerLoading = true
      getCUser(params).then((data) => {
        if (data.status) {
          this.customerLoading = false
          this.customerData = data.data.records
          this.customerPage.total = data.data.total
        }
      })
    },

    /* 取消 */
    cancel() {
      this.box = false
      this.$refs.crud.toggleSelection()
      this.$refs.customer_crud.toggleSelection()
    },
    /* 审核 */
    celCustomer(row) {
      let params = {
        id: row.authId,
      }
      this.srcList = []
      this.authId = row.authId
      this.celLoading = true
      this.openCel = true
      searchAuthById(params).then((res) => {
        if (res.status) {
          this.celLoading = false
          this.shList = res.data
          res.data.fileList.forEach((item) => {
            this.run(item.base64Code, res.data.printBk)
          })
          //this.srcList = res.data.fileList.map(item=>item.base64Code)
        }
      })
    },
    /* 审核保存 */
    shSubmit() {
      let params = {
        authId: this.shList.authId,
        status: this.shList.ty,
      }
      if (this.shList.ty == '3') {
        params.comment = this.shList.mark
      } else {
        params.comment = ''
      }
      this.$refs['sh'].validate((valid) => {
        if (valid) {
          updateApproveAuth(params).then((res) => {
            if (res.status) {
              this.openCel = false
              this.$message({
                type: 'success',
                message: '操作成功!',
              })
              this.onLoad(this.page)
            }
          })
        }
      })
    },

    checkOpen(row) {
      this.yshList = {}
      this.ysrcList = []
      let params = {
        id: row.authId,
      }
      this.openCell = true
      this.checkLoading = true
      searchAuthById(params).then((res) => {
        if (res.status) {
          this.checkLoading = false
          this.yshList = res.data
          res.data.fileList.forEach((item) => {
            this.run(item.base64Code, res.data.printBk)
          })
          //this.ysrcList = res.data.fileList.map(item=>item.base64Code)
        }
      })
    },
    // 添加水印1
    async run(imgUrl, markText) {
      // 1.图片路径转成canvas
      const tempCanvas = await this.imgToCanvas(imgUrl)
      // 2.canvas添加水印
      //const markText = '我是水印'
      const canvas = this.addWatermark(tempCanvas, markText)
      // 3.canvas转成img
      const img = this.convasToImg(canvas)
      // 查看效果
      if (this.openCel) {
        this.srcList.push(img.src)
      } else if (this.openCell) {
        this.ysrcList.push(img.src)
      }
    },
    start(row, val) {
      let params = {
        authId: row.authId,
        openStatus: val,
      }
      updateApprOpenSatus(params).then((res) => {
        if (res.status) {
          this.$message({
            type: 'success',
            message: '操作成功!',
          })
          this.onLoad1(this.page)
        } else {
          this.$message({
            type: 'error',
            message: `${res.msg}`,
          })
        }
      })
    },
    save(params) {
      // addToPurpose(params).then((data) => {
      //     if (data.status) {
      //         this.$message({
      //             type: "success",
      //             message: "操作成功!"
      //         });
      //         this.onLoad();
      //         this.openDialog = false;
      //         this.$refs.auth.resetForm();
      //     } else {
      //         this.$message.error(data.msg);
      //     }
      // }, error => {
      //     window.console.log(error);
      // });
    },
    //新增取消
    handleReset(val) {
      this.openDialog = val
    },
    addFromSour() {
      // 显示窗口
      this.openDialog = true
    },

    onSearch() {
      let params = {
        shtyxydm: this.form.shtyxydm,
      }
      getAllC(params).then((res) => {
        if (res.status) {
          this.show = true
          this.dataList = res.data
        }
      })
    },

    submit(e) {
      let form = []
      if (this.customerSelectionList.length === 0) {
        this.$message.warning('请选择至多一条数据')
        return
      } else if (this.customerSelectionList.length > 1) {
        this.$message.warning('请选择至多一条数据')
        return
      } else {
        // form = this.customerSelectionList;
        // let form = new Map();
        // form.set("eid",this.customerSelectionList[0].eid)
        var shtyxydms = []
        shtyxydms.push(this.selectionList[0].shtyxydm)
        // form.set("shtyxydms",shtyxydms)

        // form.eid = this.customerSelectionList[0].eid;

        if (e == 'up') {
          upAssign(
            this.selectionList[0].shtyxydm,
            this.customerSelectionList[0].eid
          ).then((data) => {
            if (data.status) {
              this.box = false
              this.$message.success(data.msg)
              this.customerSelectionList = []
              this.selectionList = []
              this.$refs.crud.toggleSelection()
              this.$refs.customer_crud.toggleSelection()
              this.onLoad(this.page)
            } else {
              this.$message.error(data.msg)
            }
          })
        } else {
          assignC({
            shtyxydms: shtyxydms,
            eid: this.customerSelectionList[0].eid,
          }).then((data) => {
            if (data.status) {
              this.box = false
              this.$message.success(data.msg)
              this.customerSelectionList = []
              this.selectionList = []
              this.$refs.crud.toggleSelection()
              this.$refs.customer_crud.toggleSelection()
              this.onLoad(this.page)
            } else {
              this.$message.error(data.msg)
            }
          })
        }
      }
    },

    uploadFile() {
      this.uploadLoading = false
      var that = this
      this.fileList = []
      this.uploadTemplateDialog = true
      setTimeout(function () {
        that.$refs.upload.clearFiles()
      }, 100)
    },
    handleExceed(files, fileList) {
      this.$message.warning('只能选择1个文件!')
    },
    submitUpload() {
      this.uploadLoading = true
      var that = this
      setTimeout(function () {
        if (that.$refs.upload.$children[0].fileList.length == 1) {
          that.$refs.upload.submit()
        } else {
          that.uploadLoading = false
          that.$message({
            type: 'error',
            showClose: true,
            duration: 3000,
            message: '请选择文件!',
          })
        }
      }, 100)
    },
    handleRemove(file, fileList) {
      //console.log(file,fileList);
    },
    handlePreview(file) {
      //console.log(file);
    },
    beforeUpload(file) {
      var that = this
      //文件类型
      var fileName = file.name.substring(file.name.lastIndexOf('.') + 1)
      if (fileName != 'xls') {
        that.uploadTemplateDialog = false
        that.$message({
          type: 'error',
          showClose: true,
          duration: 3000,
          message: '文件类型不是.xls文件!',
        })
        return false
      }
      //读取文件大小
      var fileSize = file.size
      console.log(fileSize)
      if (fileSize > 1048576) {
        that.uploadTemplateDialog = false
        that.$message({
          type: 'error',
          showClose: true,
          duration: 3000,
          message: '文件大于1M!',
        })
        return false
      }
      that.downloadLoading = that.$loading({
        lock: true,
        text: '数据导入中...',
        spinner: 'el-icon-loading',
        background: 'rgba(0,0,0,0.7)',
      })
      let fd = new FormData()
      fd.append('file', file)
      fd.append('_t1', new Date())
      axios({
        method: 'post',
        url: '/upload/' + new Date().getTime(),
        data: fd,
        headers: {
          'Content-Type':
            'multipart/form-data;boundary=' + new Date().getTime(),
        },
      })
        .then((rsp) => {
          that.downloadLoading.close()
          that.uploadLoading = false
          let resp = rsp.data
          if (resp.resultCode == 200) {
            that.uploadTemplateDialog = false
            that.$message.success(resp.resultMsg)
            //that.queryData();//更新数据
          } else {
            that.uploadTemplateDialog = false
            that.$message({
              type: 'error',
              showClose: true,
              duration: 60000,
              message: resp.resultMsg,
            })
          }
        })
        .catch((error) => {
          that.downloadLoading.close()
          that.uploadLoading = false
          that.uploadTemplateDialog = false
          that.$message({
            type: 'error',
            showClose: true,
            duration: 60000,
            message: '请求失败! error:' + error,
          })
        })
      return false
    },
  },
}
</script>

<style scoped="scoped" lang="scss">
/deep/ .avue-crud__pagination {
  text-align: center;
}
/deep/ .avue-crud__menu{
  min-height:0px !important;
}
.chart-container {
  display: flex;
}
#el-tab-pane {
  font-size: 40px;
  font-weight: bold;
}
.dialog-footer {
  text-align: center;
  margin: 20px auto;
}
.detailtable {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  border: #e5e5e5 solid 1px;
}
.detailtable tr {
  width: 100%;
}
.detailtable td {
  padding: 8px 10px;
  text-align: left;
  line-height: 24px;
  font-size: 14px;
  color: #434343;
  border: #e5e5e5 solid 1px;
}
.detailtable td {
  font-weight: normal;
  background-color: #fff;
}
.detailtable td {
  word-break: break-all;
}
/deep/ .row {
  display: flex;
  justify-content: space-between;
}
/deep/ .el-textarea {
  width: 100%;
}
</style>
